<?php

namespace Common\Model;
use Think\Model;

class MovieLevel2V3Model extends Model {
    protected $trueTableName = 'tb_movie_level2_v3';

    public function getMovieLevel2($movie_id,$userType=null)
    {
        $where=array();
        $where['movie_id']=$movie_id;
        if(!$userType){
            $where['status']=1;
        }
        $data=$this->where($where)->order('sort')->select();
        return $data;
    }

    // 获取一个电影的二级栏目列表
    public function getOneMovieMovieLevel2($movie_id)
    {
        $where=array();
        $where['movie_id']=$movie_id;
        $where['status']=1;
        $data=$this->where($where)->field('id,name')->order('sort')->select();
        return $data;

    }

    /**
     * 获取 电影对应的第一个二级栏目的id  没有返回 0
     * @param $movie_id
     * @return int
     */
    public function getFirstMovieLevel2Id($movie_id)
    {
        if($movie_id){
            $where=array();
            $where['movie_id']=$movie_id;
            $where['status']=1;
            $data=$this->where($where)->field('id,name')->order('sort')->select();
            if($data){
                $first_id = $data[0]['id'];
                return $first_id;
            }else{
                return 0;
            }
        }else{
            return 0;
        }
    }

    /**
     * 获取 二级栏目的名字 和转换 url 地址  使用于 api调用。
     * @param $movie_id
     * @param null $userType
     * @return array|string
     */

    public function getMovieLevel2ForApi($movie_id,$userType=null)
    {
        if($movie_id){
            $where=array();
            $where['movie_id']=$movie_id;
            if(!$userType){
                $where['status']=1;
            }
            $data=$this->where($where)->field('id,name,sort')->order('sort')->select();

            $data_rel= array();

            foreach($data as $kry => $val){
                $temp_data=array();
                $temp_data['name']=$val['name'];
                $temp_data['movie_level2_id'] = $val['id'];
                $data_rel[]=$temp_data;
            }

            //var_dump($data_rel);die();
            return $data_rel;
        }else{
            return '';
        }
    }


}